<!doctype html>
<html lang="en">
  <head>
    <!-- Google Tag Manager -->
    <script>
      gtmId = window.__ACTION__.googleTagManagerId
      gtmIdValidation = /^GTM-[A-Z0-9]+$/
      if (gtmId && gtmIdValidation.test(gtmId)) {
        ;(function (w, d, s, l, i) {
          w[l] = w[l] || []
          w[l].push({
            'gtm.start': new Date().getTime(),
            event: 'gtm.js'
          })
          var f = d.getElementsByTagName(s)[0],
            j = d.createElement(s),
            dl = l != 'dataLayer' ? '&l=' + l : ''
          j.async = true
          j.src = 'https://www.googletagmanager.com/gtm.js?id=' + i + dl
          f.parentNode.insertBefore(j, f)
        })(window, document, 'script', 'dataLayer', gtmId)
      }
    </script>
    <!-- End Google Tag Manager -->
    <title>Streamline or Replace Meetings | Parabol</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta name="theme-color" content="#493272" />
    <meta
      name="description"
      content="Meetings are expensive. Parabol makes meeting time as efficient as possible or even replaces meetings with a structured collaborative process that can be done on your own time. Try our team stand-ups, check-ins, retrospectives, Sprint Poker, prioritization templates and more, free."
    />
    <link href="/manifest.json" rel="manifest" crossorigin="use-credentials" />
    <link href="__PUBLIC_PATH__/favicon.ico" rel="shortcut icon" crossorigin="" />
    <%=
      htmlWebpackPlugin.tags.headTags.map((tag) => {
        tag.attributes.crossorigin=''
        return tag
      }).join('')
    %>
    <!-- Safari sometimes kills the current service worker before it can load the initial script to load the updated one -->
    <script>
      if ('serviceWorker' in navigator) {
        let loadError = false
        let serviceWorkerUpdateFound = false

        function unregisterSW(event) {
          if (!loadError || !serviceWorkerUpdateFound) return
          location.reload()
        }

        // because the script tag is `defer` we need to attach the handler via script
        document.querySelectorAll('script').forEach((script) => {
          if (script.src) {
            script.onerror = () => {
              console.log('Error loading script ', script.src)
              loadError = true
              unregisterSW()
            }
            script.onload = () => {
              console.log('Load script ', script.src)
              loadError = false
              script.onerror = null
              script.onload = null
            }
          }
        })

        // context closed event happens because the old service worker is killed because a new one is found
        navigator.serviceWorker.getRegistration().then((reg) => {
          if (!reg) return
          reg.addEventListener('updatefound', () => {
            console.log('Service worker update found')
            serviceWorkerUpdateFound = true
            unregisterSW()
          })
        })
      }
    </script>
    <!-- End Safari hack -->
  </head>

  <body>
    <div id="root"></div>
    <%= htmlWebpackPlugin.tags.bodyTags %>
  </body>
</html>
